home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / async.zip / HANDLER.ASM < prev    next >
Assembly Source File  |  1986-10-18  |  4KB  |  198 lines

  1. int14    equ    1    ; comment out to remove int14 routines
  2. codeseg    segment para public 'CODE'
  3. dataseg    segment para public 'DATA'
  4.     extrn    _PSP_:word, $MEMRY:word
  5.     old_com_int    dd 0
  6. dataseg    ends
  7.     public old_vector_,myds
  8. old_vector_    label word
  9. old_vector    dd    0
  10. myds    dw    0
  11.  
  12. assume cs:codeseg,ds:dataseg
  13. extrn    c_handler_:near
  14. public    setup_int14_,restore_int14_,service
  15.     ; service interrupts
  16. service    proc    near
  17. snoop:
  18.     ; we've got a call we're worried about
  19.     ; push registers in opposite of the order they'll appear as formal
  20.     ; parameters to this program
  21.     push    es    ; last
  22.     push    ds    ;
  23.     push    di    ;
  24.     push    si    ;
  25.     push    dx    ;
  26.     push    cx    ;
  27.     push    bx    ;
  28.     push    ax    ;
  29.     mov    ax,cs:myds
  30.     mov    ds,ax
  31.     mov    es,ax
  32.     sti            ; enable interrupts
  33.     call c_handler_
  34.     pop    ax        ; restore registers
  35.     pop    bx
  36.     pop    cx
  37.     pop    dx
  38.     pop    si
  39.     pop    di
  40.     pop    ds
  41.     pop    es
  42.     iret        ; get outa here
  43. service    endp
  44.  
  45.  
  46. ifdef int14
  47.     ; set up the interrupt service handler
  48. setup_int14_    proc    near
  49.     push    es
  50.     mov    cs:myds,ds
  51.     nop
  52.     mov    ah,35H
  53.     mov    al,14H                            ; offset of interrupt service
  54.     int 21H
  55.     mov    word    ptr cs:old_vector,bx
  56.     mov    word    ptr cs:old_vector+2,es
  57.     pop    es
  58.     push    ds
  59.     mov    ax,cs
  60.     mov    ds,ax
  61.     mov    dx,offset service
  62.     mov    ah,25H
  63.     mov    al,14H
  64.     int    21H
  65.     pop    ds
  66.     ret                                        ; done
  67. setup_int14_    endp
  68.  
  69. restore_int14_    proc    near
  70.     push    ds
  71.     mov    dx,word ptr cs:old_vector
  72.     mov    ax,word ptr cs:old_vector+2
  73.     mov    ds,ax
  74.     mov    ah,25H
  75.     mov    al,14H
  76.     int 21H
  77.     pop    ds
  78.     ret
  79. restore_int14_    endp
  80.  
  81.     public    call_rom_
  82. call_rom_    proc    near
  83.     push    bp
  84.     mov    bp,sp
  85.     mov    ax,[bp+4]    ; get ax parm
  86.     mov    dx,[bp+6]
  87.     mov    cx, word ptr cs:old_vector
  88.     or    cx, word ptr cs:old_vector+2
  89.     jnz chain_call
  90.     int 14
  91.     jmp outahere
  92. chain_call:
  93.     pushf
  94.     call dword ptr cs:old_vector
  95. outahere:
  96.     pop    bp
  97.     ret
  98. call_rom_    endp
  99.  
  100.     public    terminate_
  101. terminate_    proc    near
  102.     ;calculate memory size in paragraphs
  103.     mov        dx,$MEMRY
  104.     add        dx,15        ;bump to next even paragraph
  105.     mov        cx,4        ;move 4 places right
  106.     shr        dx,cl        ;
  107.     mov    ax,_PSP_        ; first paragraph of my program allocation
  108.     mov    cx,ds            ; current data segment
  109.     sub    cx,ax            ; subtract psp from ds to get size of psp
  110.     add    dx,cx            ; add to number of paragraphs in data segment
  111.     mov        al,0        ;exit code of 0
  112.     mov        ah,31H        ;terminate and stay resident
  113.     int        21H            ;go do it
  114.     ret                    ;should never return!!!
  115. terminate_    endp
  116. endif
  117.  
  118.     ; core routines for communications
  119.     
  120.     extrn comserv_:near
  121. comservice    proc    near
  122.     push    es    ; last
  123.     push    ds    ;
  124.     push    di    ;
  125.     push    si    ;
  126.     push    dx    ;
  127.     push    cx    ;
  128.     push    bx    ;
  129.     push    ax    ;
  130.     mov    ax,cs:myds
  131.     mov    ds,ax
  132.     mov    es,ax
  133.     sti            ; enable interrupts
  134.     call comserv_
  135.     pop    ax        ; restore registers
  136.     pop    bx
  137.     pop    cx
  138.     pop    dx
  139.     pop    si
  140.     pop    di
  141.     pop    ds
  142.     pop    es
  143.     iret        ; get outa here
  144. comservice    endp
  145.  
  146.     public    setup_comint_
  147. setup_comint_    proc    near
  148.     push    bp
  149.     mov    bp,sp
  150.     push    es        ; es used in get vector call
  151.     mov    al,4[bp]    ; pick up int num
  152.     mov    ah,35H        ; get vector
  153.     int 21H
  154.     ; store it away
  155.     mov    word ptr old_com_int,bx
  156.     mov    word ptr old_com_int+2,es
  157.     pop    es            ; restore es
  158.     ; set up new vector
  159.     mov    ah,25H
  160.     mov    al,4[bp]    ; pick up int num again
  161.     push    ds        ; ds used in set vector call
  162.     mov    dx,cs        ; get segment
  163.     mov    ds,dx        ;
  164.     mov    dx,offset comservice    ; get offset
  165.     int 21H            ; go do it
  166.     pop    ds            ; restore ds
  167.     pop    bp
  168.     ret
  169. setup_comint_    endp
  170.  
  171.     public    restore_comint_
  172. restore_comint_    proc    near
  173.     push    bp
  174.     mov    bp,sp
  175.     push    ds
  176.     lds    dx,old_com_int
  177.     mov    al,4[bp]    ; pick up int num
  178.     mov    ah,25H        ; set vector
  179.     int 21H
  180.     pop    ds
  181.     pop    bp
  182.     ret
  183. restore_comint_    endp
  184.  
  185.     public    cli_,sti_
  186. cli_    proc    near
  187.     cli
  188.     ret
  189. cli_    endp
  190.  
  191. sti_    proc    near
  192.     sti
  193.     ret
  194. sti_    endp
  195.  
  196. codeseg    ends
  197.     end
  198.